﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Loja.Data;

namespace Loja.Business
{
    public class CategoriaBLL
    {
        public List<SelectListItem> GetCategorias()
        {
            IRepository<Categoria> categoriaRepository = new DataRepository<Categoria>();

            var categ = categoriaRepository.Find(c => c.IdPai == null);
            var categSelectList = new SelectList(categ, "IdCategoria", "Descricao").ToList();
            categSelectList.Insert(0, new SelectListItem() { Selected = true, Text = "Selecione", Value = "" });

            return categSelectList;
        }

        public List<SelectListItem> GetSubcategorias(int idPai)
        {
            IRepository<Categoria> categoriaRepository = new DataRepository<Categoria>();

            var categ = categoriaRepository.Find(c => c.IdPai == idPai);
            var categSelectList = new SelectList(categ, "IdCategoria", "Descricao").ToList();
            categSelectList.Insert(0, new SelectListItem() { Selected = true, Text = "Selecione", Value = "" });

            return categSelectList;
        }
    }
}
